<h2 style='text-align:center'>症状编辑</h2>

<div style='margin-bottom:20px'>
	<button id='main_type1_viewAdd'>添加症状</button>
	<div id='main_type1_addArea' style='display:none'>
		<input type="text" placeholder='输入症状名' id='main_type1_inp' />
		<button id='main_type1_addBtn'>提交</button>
		<button id='main_type1_addCancel'>取消</button>
	</div>
</div>

<div>
	<div style='font:normal bold 18px/40px Georgia'>
		<span id='main_type1_edit_className'>分类名：</span>
		<span style='margin-left:30px'>
			<button id='main_type1_viewRname'>重命名</button>
			<span id='main_type1_rnameArea' style='display:none'>
				<input type="text" placeholder='输入分类名' id='main_type1_rnameInp' />
				<button id='main_type1_rnameAddBtn'>提交</button>
				<button id='main_type1_rnameAddCancel'>取消</button>
			</span>
		  　<button id='main_type1_delTypeName'>删除分类</button>
	  	</span>
	 </div>
	<div style='margin-left:40px;word-break:break-all' id='main_type1_subList'>
		<!--div style='margin:10px 0'>
			症状1症状1症状1症状1症状1症状1症状1
			<span style='margin-left:30px'>上移</span>
			<span style='margin-left:10px'>删除</span>
		</div-->
			<h3 style='text-align:center;color:red'>暂无数据</h3>
	</div>
</div>

<div style='text-align:center;margin:30px'><button onclick='_main_type1_back()'>返回</button></div>


<script>

	//上页保存的分类信息
	if(!tmp_item){
		_main_type1_back();
	}
	//C(tmp_item);



	//删除分类
	$('#main_type1_delTypeName').click(function(){
		if(tmp_item.subList.length > 0){
			A('分类下症状不为空！');return;
		}
		_delClass(tmp_item.id);
	});


	//遍历症状
	if(tmp_item.subList && tmp_item.subList.length > 0){
		//排序
		var tmp = '';
		for(var i=0;i<tmp_item.subList.length-1;i++){
			for(var j=0;j<tmp_item.subList.length-1;j++){
				if(parseInt(tmp_item.subList[j].orders) > parseInt(tmp_item.subList[j+1].orders)){
					tmp = tmp_item.subList[j+1];
					tmp_item.subList[j+1] = tmp_item.subList[j];
					tmp_item.subList[j] = tmp ;
				}
			}
		}
	

		var tmp_str = '';
		for(var i=0;i<tmp_item.subList.length;i++){
			tmp_str += "<div style='margin:10px 0'>"+tmp_item.subList[i].name;
				tmp_str += "<span style='margin-left:35px;font-size:12px' >序号："+tmp_item.subList[i].orders+"</span>";
				tmp_str += "<span style='margin-left:35px;font-size:12px' onclick=_upDown("+tmp_item.subList[i].id+",'up')>下移</span>";
				tmp_str += "<span style='margin-left:15px;font-size:12px' onclick=_upDown("+tmp_item.subList[i].id+",'down')>上移</span>";
				tmp_str += "<span style='margin-left:15px;font-size:12px' onclick=_delSubItem("+tmp_item.subList[i].id+")>删除</span>";
			tmp_str += "</div>";
		}
		$('#main_type1_subList').html(tmp_str);
	}


	//删除症状
	function _delSubItem(id){
		if(_confirm() == 'err'){
			return;
		}
		Notice2(1);
		var data = {
			type:'delSubItem',
			id:id
		}
		Ajax2(data,function(res){
			Notice2();
			if(res.stat == 'ok'){
				_initData();	//初始化数据
				setTimeout(function(){
					_type1_loadEditPage(tmp_index);
					A('操作成功！');
				},500)
			}else{
				A('操作异常！');
			}
		},1)
	}

	//删除分类
	function _delClass(id){
		if(_confirm() == 'err'){
			return;
		}
		Notice2(1);
		var data = {
			type:'delSubItem',
			id:id
		}
		Ajax2(data,function(res){
			Notice2();
			if(res.stat == 'ok'){
				//A('操作成功！');
				location.reload(1);
			}else{
				A('操作异常！');
			}
		},1)
	}


	//症状的上移或下移
	function _upDown(id,type){
		Notice2(1);
		var data = {
			type:'itemUpDown',
			ctype:type,
			id:id
		}
		Ajax2(data,function(res){
			Notice2();
			if(res.stat == 'ok'){
				_initData();	//初始化数据
				setTimeout(function(){
					_type1_loadEditPage(tmp_index);
				},500)
			}
		});
	}

	//重命名相关
	$('#main_type1_rnameAddBtn').click(function(){
		Notice2(1);
		var name = $('#main_type1_rnameInp').val().trim();
		var data = {
			type:'classRname',
			name:name,
			id:tmp_item.id
		}
		Ajax2(data,function(res){
			Notice2();
			if(res.stat == 'ok'){
				//A('操作成功！');
				_initData();	//初始化数据
				$('#main_type1_edit_className').text(name);	//修改临时显示分类名
			}else{
				A('分类名存在或操作异常！');
			}
		})
		_main_type1_rnameAreaInit();
	});
	$("#main_type1_viewRname").click(function(){
		$(this).hide();
		$('#main_type1_delTypeName').hide();
		$('#main_type1_rnameArea').show();
	});
	$('#main_type1_rnameAddCancel').click(function(){
		_main_type1_rnameAreaInit();
	});
	function _main_type1_rnameAreaInit(){
		$('#main_type1_viewRname,#main_type1_delTypeName').show();
		$('#main_type1_rnameArea').hide();
		$('#main_type1_rnameInp').val('');
	}



	//添加症状
	$('#main_type1_addBtn').click(function(){
		Notice2(1);
		var v = $('#main_type1_inp').val().trim();
		var data = {
			type:'addClassItem',
			name:v,
			classId:tmp_item.id
		}
		Ajax2(data,function(res){
			Notice2();
			if(res.stat == 'ok'){
				//_main_type1_addAreaInit();
				_initData();	//初始化数据
				setTimeout(function(){
					_type1_loadEditPage(tmp_index);
				},500)
				A('操作成功！');
			}else{
				A('症状已存在或操作失败！');
			}
		})

	});


	//展示分类名
	$('#main_type1_edit_className').text(tmp_item.name);









	//添加症状相关
	$("#main_type1_viewAdd").click(function(){
		$(this).hide();
		$('#main_type1_addArea').show();
	});
	$('#main_type1_addCancel').click(function(){
		_main_type1_addAreaInit();
	});


	function _main_type1_addAreaInit(){
		$('#main_type1_viewAdd').show();
		$('#main_type1_addArea').hide();
		$('#main_type1_inp').val('');
	}


	//返回上一级
	function _main_type1_back(){
		$('#type1_area1').show();
		$('#type1_area2').hide();
	}



</script>